package ahut2020.day16final;


import java.util.Arrays;

public class Factorial3 {
    static int[] F = new int[13];

    static int factorial(int n) {//DynamicProgramming
        if (F[n] != 0) {//查表 O(1)
            return F[n];
        }
        if (n < 1) return F[n] = 1;//及时存储计算结果
        return F[n] = factorial(n - 1) * n;//及时存储计算结果

    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(F));
        //  System.out.println(factorial(5));
        factorial(3);
        System.out.println(Arrays.toString(F));
        System.out.println(factorial(2));
        System.out.println(Arrays.toString(F));
        System.out.println(factorial(4));
        System.out.println(Arrays.toString(F));
        factorial(12);
        System.out.println(Arrays.toString(F));
    }
}
